<?php

class XDao_ModelI18n extends XDao_Model
{
    // language
    protected $langId;

	public function __construct($langId = null, $dbLink = null)
	{
		$this->setLangId($langId);
		if (empty($dbLink))
		{
			$this->db = XDb::getInstance();
		}
		else
		{
			$this->db = $dbLink;
		}
	}

	public function setLangId($langId)
	{
		if (!is_null($langId))
		{
			$this->langId = $langId;
		}
	}

	/**
	 * Instantiate an empty item for current table.
	 *
	 * @return  object
	 */
	public function fetch_new()
	{
		$finder = new XDao_FinderI18n($this->schema(), $this->langId);
		return $finder->fetch_new();
	}
	

	/**
	 * Instantiates a Finder object for current model.
	 *
	 * @return  object
	 */
	public function find()
	{
		return new XDao_FinderI18n($this->schema(), $this->langId);
	}

	/**
	 * Returns the schema for current object. Also caches it locally.
	 *
	 * @return object
	 */
	public function schema()
	{
		// Table name must be set
		if (!isset($this->table)) self::trigger_error(self::ERR_TABLE_NOT_SET);

		if (isset($this->schemas[$this->table])) return $this->schemas[$this->table];

		$schema = parent::schema();

		// Check table relationships
		if (isset($this->translated_cols))
		{
			$schema->translated_cols = $this->translated_cols;
		}
		
		$this->schemas[$this->table] = $schema;
		
		return $schema;
	}
	
}

?>